<template>
	<view class="question">
		<view class="top">
			<progress class="progress" :percent="countPercent()" stroke-width="4" active active-mode="forwards"
				activeColor="#fcd22e" />
			<div class="top-text"> {{correntIndex.length + errorIndex.length}}/{{questionData.length}}</div>
		</view>
		<view class="content">
			<swiper @change="changeCurrent" class="swiper" :current="swiperCurrent"
				:style="{ height: swiperHeight + 'px' }">
				<swiper-item v-for="(item,index) in questionData" :key="index">
					<view :id="'content-wrap' + index">
						<view class="topic-area">

							<view class="topic-type">{{index + 1}} {{item.type === '1' ? '单选题' : '多选题'}}</view>
							<view class="examQuestion">{{item.examQuestion}}</view>
						</view>


						<block v-if="item.type === '1'">
							<view :class="getSelectedStatus(index,itema)" v-for="(itema,indexa) in item.options"
								:key="indexa"
								@click="judgment(index,indexa,itema.select_id,item.correct_id,itema.isCorrect)">
								<text>{{sequence[indexa]}}</text>

								<text>{{itema.select}}</text>
							</view>
							<button class="submit" v-if="!item.answered"
								:type="item.store_check_id.length >= 1 ? 'primary' : 'default'"
								:disabled="item.store_check_id.length >= 1 ? false : true"
								@click="submit1(index,item.store_check_id,item.correct_id,item.options,item._id)">确定</button>
						</block>

						<block v-if="item.type === '2'">
							<view :class="getSelectedStatus(index,itema)" v-for="(itema,indexa) in item.options"
								:key="indexa"
								@click="multipleChoice(index,indexa,itema.select_id,item.correct_id,itema.isCorrect,item.store_check_id)">
								<!-- <view :class="`${itema.icon_url}`" v-for="(itema,indexa) in item.options" :key="indexa"> -->
								<text>{{sequence[indexa]}}</text>

								<text>{{itema.select}}</text>
							</view>

							<button :class="item.store_check_id.length >= 2 ? 'submit' : ''" v-if="!item.answered"
								:type="item.store_check_id.length >= 2 ? 'primary' : 'default'"
								:disabled="item.store_check_id.length >= 2 ? false : true"
								@click="subMit(index,item.store_check_id,item.correct_id,item.options,item._id)">确定</button>
						</block>
						<block v-if="item.answered">
							<view class="middle">
								<view class="answer-box">
									<view class="correct-answer">
										<text>答案：</text>
										<text v-for="(itema,indexa) in item.correct_id" :key="index">{{itema}}</text>
										<!-- <text v-if="item.type == 1">{{item.correct_id[0]}}</text> -->
									</view>
									<view class="store_check">
										<text>你的答案：</text>
										<text v-for="(itema,indexa) in item.store_check_id"
											:key="index">{{itema}}</text>
									</view>
								</view>
								<view class="correctRate">
									全网正确率：{{(item.correct * 100 / item.done).toFixed(0)}}%
								</view>
								<view class="collect" v-if="!item.collectStatus">
									<view class="collect-text">
										我是蒙对的
									</view>
									<view class="collect-button" @click="collect(index,item._id)">
										加入错题集
									</view>
								</view>
								<view class="collect" v-else="item.collectStatus">
									<view class="collect-text">
										手误点错
									</view>
									<view class="collect-button" @click="removeCollect(index,item._id,item.chapterId)">
										移除错题集
									</view>
								</view>
							</view>

							<view class="tabs">
								<view class="tabs-type">
									<view :class="tabId == 1 ? 'item tab-selected' : 'item'" @click="changeTab(1)">
										题目解析
									</view>
									<view :class="tabId == 2 ? 'item tab-selected' : 'item'" @click="changeTab(2)">
										研友笔记
									</view>
									<view :class="tabId == 3 ? 'item tab-selected' : 'item'" @click="changeTab(3)">
										我的笔记
									</view>
								</view>
							</view>
							<view class="analyze" v-show="tabId == 1">
								<view class="analyze-title">
									<text>题目解析</text>
								</view>
								<view>{{item.analyse}}</view>
							</view>
							<view class="other-note" v-show="tabId == 2">
								<view class="other-note-title">
									<text>研友笔记</text>
								</view>
								<view class="note-operate">
									<view class="sort-box">
										<view :class="orderType == 1 ? 'order-approve note-active' : 'order-approve'"
											@click="changeOrder(1)">
											按点赞排序
										</view>
										<view :class="orderType == 2 ? 'order-time note-active' : 'order-time'"
											@click="changeOrder(2)">
											按时间排序
										</view>
									</view>
									<view class="allNote" @click="goAllNote">
										查看全部笔记
									</view>
								</view>
								<view class="note-box">


									<view class="item" v-for="(item,index) in otherNote" :key="index">
										<view class="note-top">
											<view class="img">
												<image :src="item.avatarUrl ? item.avatarUrl : 'https://pic.imgdb.cn/item/65cdb4349f345e8d03c21fa4.png'" mode=""></image>
											</view>
											<view class="user-name">
												{{item.userName}}
											</view>
											<view class="note-time">
												{{getTime(item.date)}}
											</view>
										</view>
										<view class="note-content">
											{{item.content}}
										</view>
										<view class="note-approve">
											{{item.approve}}
											<view class="img" @click="like(item._id,index)">
												<image v-if="item.like" src="../../static/approve-active.png" mode="">
												</image>
												<image v-else src="../../static/approve.png" mode=""></image>
											</view>
										</view>
										<view class="note-report" @click="report(item._id)">
											<view class="img">
												<image src="../../static/report.png" mode=""></image>
											</view>
										</view>
									</view>



								</view>
							</view>
							<view class="my-note" v-show="tabId == 3">

								<view @click="openDialog" class="addNode">新增笔记</view>
								<view class="my-note-title">
									<text>我的笔记</text>
								</view>
								<view class="note-operate">
									<view class="sort-box">
										<view :class="orderType == 1 ? 'order-approve note-active' : 'order-approve'"
											@click="changeOrder(1)">
											按点赞排序
										</view>
										<view :class="orderType == 2 ? 'order-time note-active' : 'order-time'"
											@click="changeOrder(2)">
											按时间排序
										</view>
									</view>

								</view>
								<view>

									<view class="item" v-for="(item,index) in myNote" :key="index">
										<view class="note-top">
											<view class="img">
												<image :src="item.avatarUrl ? item.avatarUrl : 'https://pic.imgdb.cn/item/65cdb4349f345e8d03c21fa4.png'" mode=""></image>
											</view>
											<view class="user-name">
												{{item.userName}}
											</view>
											<view class="note-time">
												{{getTime(item.date)}}
											</view>
										</view>
										<view class="note-content">
											{{item.content}}
										</view>

									</view>
								</view>
							</view>
						</block>
					</view>

				</swiper-item>
			</swiper>
			<view class="temp-bottom">

			</view>
			<uni-popup ref="inputDialog" type="dialog">
				<uni-popup-dialog ref="myNodeInput" mode="input" title="输入内容" placeholder="请输入内容"
					@confirm="dialogInputConfirm"></uni-popup-dialog>
			</uni-popup>

			<page-container :show="showPopup" @beforeleave="showPopup = false" @clickoverlay="showPopup = false">
				<view class="popup-view">
					<view class="topic-number">
						<view class="single">
							<view class="text">
								单选
							</view>
							<view class="item">
								<text v-for="(item,index) in single" :key="index" :class="getTestStyle(index)"
									@click="numericalOrder(index)">{{item}}</text>
							</view>
						</view>
						<view class="multiple">
							<view class="text">
								多选
							</view>
							<view class="item">
								<text v-for="(item,index) in multiple" :key="index"
									:class="getTestStyle(single + index)"
									@click="numericalOrder(single + index)">{{single + 1 + index}}</text>
							</view>
						</view>
					</view>
				</view>
			</page-container>
			<view class="bottom-operate">
				<!-- <view class="collect">
					<view class="">
						收藏
					</view>
					<view class="img">
						<image src="../../static/collect.png" mode=""></image>
					</view>
				</view> -->

				<!-- 	<view class="error">
					<view class="">
						纠错
					</view>
					<view class="img">
						<image src="../../static/error.png" mode=""></image>
					</view>
				</view> -->
				<view class="question-card" @click="showModal">
					<view class="">
						答题卡
					</view>
					<view class="img">
						<image src="../../static/question-card.png" mode=""></image>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		onShow,
		onLoad
	} from "@dcloudio/uni-app"
	import util from '../../util/index.js'
	import {
		ref,
		onMounted,
		computed,
	} from 'vue'
	import moment from "moment";
	import {
		getCurrentInstance
	} from 'vue';
	const instance = getCurrentInstance(); // 获取组件实例

	// 存储答对的题的下标
	const correntIndex = ref([])
	// 存储答错的题的下标
	const errorIndex = ref([])
	const tabId = ref(1);
	// 滑块顺序，下标从0开始
	const swiperCurrent = ref(0)
	const single = ref(0); // 单项数量
	const multiple = ref(0); // 多选数量
	const ids = ref({})
	const inputDialog = ref()
	const myNodeInput = ref()
	let swiperHeight = ref(0)
	let correctRate = ref(0)
	// 控制弹窗弹出
	const showPopup = ref(false)
	const fromInfo = ref("") //记录从什么地方进来
	// 当前题目的顺序
	const currentOrder = ref(1);
	const otherNote = ref([]);
	const myNote = ref([])
	const commentInput = ref('')
	const orderType = ref(1);
	const report = (id) => {
		uni.showModal({
			title: '提示',
			content: '是否举报改笔记',
			success: function(res) {
				if (res.confirm) {
					uni.request({
						url: util.baseUrl + '/wxapi/comment/report',
						method: 'POST',
						data: {
							commentId: id
						},
						success: (res) => {
							if (res.data.code == 200) {
								uni.showToast({
									title: '举报成功，等待管理员的审核',
									duration: 1500,

								});
							}
						}
					})
				} else if (res.cancel) {
					console.log('用户点击取消');
				}
			}
		});
	}
	const changeOrder = (type) => {
		orderType.value = type
		getCommentList(tabId.value, type)
	}
	const percent = ref(0); // 多选数量
	const like = (id, index) => {
		if (!otherNote.value[index].like) {
			otherNote.value[index].approve++
			uni.request({
				url: util.baseUrl + '/wxapi/comment/approveComment',
				method: 'POST',
				data: {
					commentId: id
				},
				success: () => {

				}
			})
		}

		otherNote.value[index].like = true

	}
	onLoad((query) => {
		
		 ids.value = JSON.parse(query.ids)
		if(query.from != "err") {
			console.log('errerrerr')
			questionData.value = JSON.parse(decodeURIComponent(query.record))
			singleAndMultipleNum()
		}
		if (query.from == "err") { // 记录来着什么地方 现在只有另外一个错题集
		    goErrorList()
			fromInfo.value = query.from
			
		}
		console.log('questionData.value', questionData.value)
		
		
		console.log('ids.value', ids.value)
		if (query.lateDone) {
			swiperCurrent.value = query.lateDone
		
			setSwiperHeight()
		}
		
		
	// 	console.log('ids.value', ids.value)
	
	// 	console.log('single.value', single.value)
	// 	console.log('multiple.value', multiple.value)
		// getQuestion(query.id);
	})
	const singleAndMultipleNum = () => {
		// 判断单项和多选的数量
		questionData.value.forEach((item, index) => {
			if (item.type == 1) {
				single.value = single.value + 1;
			} else {
				multiple.value = multiple.value + 1;
			}
			if (item.status == 1) {
				errorIndex.value.push(index)
			} else if (item.status == 2) {
				correntIndex.value.push(index)
			}
		
		})
	}
	const getTime = (time) => {
		return moment(time).format("YYYY-MM-DD HH:mm:ss")
	}
	const openDialog = () => {
		//console.log('inputDialogRef',inputDialogRef)
		inputDialog.value.open()
	}
	const dialogInputConfirm = (value) => {
		const userInfo = uni.getStorageSync('userInfo')
		// console.log('questionId: questionData.value[swiperCurrent]',e)
		uni.request({
			url: util.baseUrl + '/wxapi/comment/docomment',
			method: 'POST',
			data: {
				chapterId: ids.value.chapterId,
				userId: userInfo._id,

				seriesId: ids.value.seriesId,
				teacherId: ids.value.teacherId,
				questionId: questionData.value[swiperCurrent.value]._id,
				content: value,
				userName: userInfo.userName,
				avatarUrl:userInfo.avatarUrl
			},
			success: () => {
				getCommentList(3, orderType.value);
				myNodeInput.value.val = ''

			}
		})

	}
	const getCommentList = (tab, orderType) => {
		console.log('tab', tab)
		console.log('swiperCurrent.value', swiperCurrent.value)
		const userInfo = uni.getStorageSync('userInfo')
		let userId = ''
		if (tab == 3) {
			userId = userInfo._id
		} else {
			userId = 'undefined'
		}
		uni.request({
			url: util.baseUrl + '/wxapi/comment/getCommentList',
			method: 'GET',
			data: {
				userId: userId,
				questionId: questionData.value[swiperCurrent.value]._id,
				orderId: orderType
			},
			success: (res) => {
				if (tab == 2) {
					otherNote.value = res.data.data.result
					console.log('otherNote.value', otherNote.value)
				} else {
					myNote.value = res.data.data.result
				}
				setTimeout(() => {
					setSwiperHeight()
				}, 100)
			}
		})
	}
	//动态设置swiper的高度
	const setSwiperHeight = () => {
		let element = "#content-wrap" + swiperCurrent.value;
		let query = uni.createSelectorQuery().in(instance);
		console.log('query', query)
		query.select(element).boundingClientRect();
		query.exec((res) => {

			if (res && res[0]) {
				swiperHeight.value = res[0].height + 30;
				console.log('res', res)
			}
		});
	}
	const inputDialogToggle = () => {

	}
	const showModal = () => {

		showPopup.value = true
	}
	const changeTab = (id) => {
		tabId.value = id
		if (id == 3 || id == 2) {
			getCommentList(id, orderType.value);
		}

	}

	const collect = (index, id) => {
		const userInfo = uni.getStorageSync('userInfo')
		questionData.value[index].collectStatus = true
		uni.request({
			url: util.baseUrl + '/wxapi/wxQuestion/manCollectQuestion',
			method: 'POST',
			data: {
				chapterId: ids.value.chapterId,
				userId: userInfo._id,
				questionId: questionData.value[index]._id,
				seriesId: ids.value.seriesId,
				teacherId: ids.value.teacherId,
				store_check_id: questionData.value[index].store_check_id
			}
		})
	}
	const removeCollect = (index, id, chapterId) => {
		console.log('chapterId',chapterId)
		const userInfo = uni.getStorageSync('userInfo')
		questionData.value[index].collectStatus = false
		uni.request({
			url: util.baseUrl + '/wxapi/wxQuestion/removeCollectQuestion',
			method: 'POST',
			data: {
				chapterId: chapterId,
				userId: userInfo._id,
				questionId: id,
				seriesId: ids.value.seriesId,
				teacherId: ids.value.teacherId
			}
		})
	}
	const changeCurrent = (event) => {
		console.log('swiperCurrent.value', swiperCurrent.value)
		console.log('event.detail.current', event.detail.current)
		swiperCurrent.value = event.detail.current
		tabId.value = 1
		myNodeInput.value.val = ''
		setTimeout(() => {
			setSwiperHeight()
		}, 100)
	}
	const countPercent = () => {
		return (errorIndex.value.length + correntIndex.value.length) / (single.value + multiple.value) * 100
	}
	
	// 点击题目序号滚动到对应的题
	const numericalOrder = (index) => {
		swiperCurrent.value = index
		currentOrder.value = index + 1
		console.log('index', index)
		showPopup.value = false
		tabId.value = 1
		myNodeInput.value.val = ''

	}
	const getStatusRadio = (index, itema) => {
		console.log('1111')
	}
	const getSelectedStatus = (index, item) => {
		if (questionData.value[index].answered) {
			return 'select-answer ' + item.icon_url
		} else {
			if (item.isCorrect) {
				return 'select-answer selected'
			} else {
				return 'select-answer'
			}
		}
	}
	const sequence = ref(['A', 'B', 'C', 'D', 'E', 'F'])
	let questionData = ref([]);

	// 多选题选中或取消选中加上样式
	const multipTextStyle = (isCorrect) => {
		if (isCorrect) {
			return 'selected'
		} else {
			return ''
		}
	}


	const getTestStyle = (index) => {
		if (questionData.value[index].status == 2) { //选择正确的题
			return 'yes-text'
		} else if (questionData.value[index].status == 1) { //选择错误的题
			return 'no-text'
		} else {
			return ''
		}
	}
	// 提交多选
	const subMit = (index, store_check_id, correct_id, options, questionId) => {
		const isSame = store_check_id.length === correct_id.length && store_check_id.every(item => correct_id.includes(
			item))
		if (isSame) { //都选对了
			// 存储答对的题的下标
			questionData.value[index].status = 2
			correntIndex.value.push(index)
			console.log('isSame', isSame);
			questionData.value[index].collectStatus = false
			// 选择正确自动进入下一题
		} else {
			// 存储答错的题的下标
			errorIndex.value.push(index)
			questionData.value[index].status = 1
			questionData.value[index].collectStatus = true
		}
		//取出正确答案在视图层展示
		const correctId = correct_id.map(value => options.findIndex(item => item.select_id === value))
		console.log('correctId', correctId);
		correctId.forEach(item => {
			questionData.value[index].options[item].whetherSubmit = true

			questionData.value[index].options[item].icon_url = imgData.value[0]
			
		})
		// 取出错误答案在视图层上加上错误图标
		let errorId = []
		console.log('correct_id', correct_id);
		// console.log('options',options);
		options.forEach((item, index) => {
			if (!correct_id.includes(item.select_id)) {
				errorId.push(index)
			}
		})
		console.log('errorId', errorId);
		if (errorId.length > 0) {
			console.log('questionData.value[index].store_check_id', questionData.value[index].store_check_id);
			errorId.forEach(item => {
				console.log('sequence[item]', sequence[item])
				if (questionData.value[index].store_check_id.includes(sequence.value[item])) {
					questionData.value[index].options[item].icon_url = imgData.value[1]
				}
		
				questionData.value[index].options[item].whetherSubmit = true
				
			})
		}
		// 已选择了该题
		questionData.value[index].answered = true
		// 进度条
		// percent.value += 2
		nowDone()
		submitRecord(index, questionId)
	}
	const nowDone = () => { // 今日做题
		let nowRecord = uni.getStorageSync('nowRecord')
		const newDate = moment(new Date()).format("YYYY-MM-DD");
		console.log('nowRecord',nowRecord)
		
		if(nowRecord.date == newDate) {
			console.log('newDate',newDate)
			nowRecord.done = nowRecord.done + 1;
			uni.setStorageSync('nowRecord',nowRecord)
		}else {
			nowRecord = {
				date: newDate,
				done:0
			}
		
			uni.setStorageSync('nowRecord',nowRecord)
		}
	}
	// 多选题
	const multipleChoice = (index, indexa, select_id, correct_id, isCorrect, store_check_id) => {
		if (questionData.value[index].answered) return false
		// 点击可选中，也可取消选中
		if (isCorrect) {
			const indexRemove = questionData.value[index].store_check_id.findIndex(item => item === select_id)
			questionData.value[index].store_check_id.splice(indexRemove, 1)
			questionData.value[index].options[indexa].isCorrect = false
		} else {
			questionData.value[index].store_check_id.push(select_id)
			questionData.value[index].options[indexa].isCorrect = true

			// 排序ABCD
			for (let i = 0; i < questionData.value[index].store_check_id.length; i++) {
				for (let j = questionData.value[index].store_check_id.length; j > i; j--) {
					if (questionData.value[index].store_check_id[j] < questionData.value[index].store_check_id[j -
							1]) {
						let temp = questionData.value[index].store_check_id[j];
						questionData.value[index].store_check_id[j] = questionData.value[index].store_check_id[j - 1];
						questionData.value[index].store_check_id[j - 1] = temp;
					}

				}
			}
		}

	}

	const imgData = ref(['true', 'false'])
	const judgment = (index, indexa) => {

		questionData.value[index].store_check_id[0] = questionData.value[index].options[indexa].select_id
		// console.log('questionData.value[index].store_check_id[0]',questionData.value[index].store_check_id)
		questionData.value[index].options.forEach((item, index) => {
			item.isCorrect = false
		})
		questionData.value[index].options[indexa].isCorrect = true;

	}
	const goAllNote = () => {
		uni.navigateTo({
			url: '/pages/allNote/allNote?questionId=' + questionData.value[swiperCurrent.value]._id
		})
	}

	const submitRecord = (index, questionId) => {
		console.log('fromInfo.value',)
		if(fromInfo.value == '"random"') {
			return
		}
		const userInfo = uni.getStorageSync('userInfo')
		console.log('ids', ids.value)
		// 1.提交到做题记录  2.提交到错题记录
		let url = '/wxapi/wxQuestion/submitQuestion'

		if (fromInfo.value == "err") {
			url = '/wxapi/wxQuestion/submitErrQuestion'
		}
		uni.request({
			url: util.baseUrl + url,
			method: 'POST',
			data: {
				chapterId: ids.value.chapterId,

				userId: userInfo._id,
				index: index,
				sectionId:ids.value.sectionId,
				seriesId: ids.value.seriesId,
				teacherId: ids.value.teacherId,
				questionId,
				errQredoFlag:userInfo.errQredoFlag,
				status:questionData.value[index].status,
				store_check_id:questionData.value[index].store_check_id,
				lateDone:questionData.value.length - 1 != index  ? index + 1 : index
			},
			success: () => {
				setTimeout(() => {
					setSwiperHeight()
					//getStatusRadio()
				}, 100)
			}

		})
	}
	// 单项提交
	const submit1 = (index, store_check_id, correct_id, options, questionId) => { // 单选
		if (questionData.value[index].answered) return false
		// console.log('store_check_id',store_check_id[0])
		// console.log('correct_id',correct_id[0])
		const correctIndex = questionData.value[index].options.findIndex((fitem, findex) => {
			return fitem.select_id == correct_id[0]
		})
		if (correct_id[0] == store_check_id[0]) { //选择正确
			// 更新当前答案的图标为正确图标
			console.log('正确')
			// 找到正确答案的下标
			questionData.value[index].status = 2
			console.log('correctIndex', correctIndex)
			questionData.value[index].options[correctIndex].icon_url = imgData.value[0]
			questionData.value[index].options[correctIndex].isCorrect = true
			// 存储答对的题的下标
			correntIndex.value.push(index)
			// 取出正确答案的顺序
			var sequenceData = sequence.value[correctIndex]
            questionData.value[index].collectStatus = false
		} else { //选择错误
			/* 
			当前项加上错误图标，将正确项加上正确图标 
			 */
			console.log('错误')
			questionData.value[index].status = 1
			questionData.value[index].collectStatus = true
			// 取出当前选择的下标
			const correntIndex = questionData.value[index].options.findIndex((fitem, findex) => {
				return fitem.select_id == store_check_id[0]
			})
			questionData.value[index].options[correntIndex].icon_url = imgData.value[1]
			// 取出正确答案的下标
			questionData.value[index].options[correctIndex].icon_url = imgData.value[0]
			// questionData.value[index].options[indexa].isCorrect = true
			questionData.value[index].options[correctIndex].isCorrect = true
			// 存储答错的题的下标
			errorIndex.value.push(index)
			// 取出正确答案的顺序
			var sequenceData = sequence.value[correctIndex]
		}
		// 取出正确答案的顺序更新数据
		questionData.value[index].correct_answerd = [sequenceData]
		// 已选择了该题
		questionData.value[index].answered = true
		// 进度条
		// percent.value += 2
		console.log('chapterId:ids.value.chapterId', ids.value.chapterId);
		nowDone()
		submitRecord(index, questionId)
	}
	const getQuestion = (id) => {
		console.log('getQuestion')
		uni.request({
			url: util.baseUrl + '/adminapi/question/list/' + id,
			method: 'GET',
			success: (res) => {
				console.log(res.data);
				questionData.value = res.data.data


			},
			fail: () => {

			}
		});
	}
	const confirmRedo = () => {
		uni.showModal({
			title: '提示',
			content: '是否重刷错题',
			success: function(res) {
				console.log('sucess')
				const userInfo = uni.getStorageSync('userInfo')
				if (res.confirm) {
					questionData.value.forEach((item) => {
						item.answered = false
						item.status = 0
						item.store_check_id = []
						item.options.forEach((item2) => {
							item2.icon_url = ""
							item2.isCorrect = false
						})
					})
					console.log('questionData.value', questionData.value)
					uni.request({
		
						url: util.baseUrl + '/wxapi/wxQuestion/redoErr',
						method: 'POST',
						data: {
							seriesId: ids.value.seriesId,
							userId: userInfo._id,
							sectionId:ids.value.sectionId,
							
						},
						success: (res) => {
							if (res.data.code == 200) {
								uni.showToast({
									title: '清除记录成功',
									duration: 1500,
		
								});
								correntIndex.value = []
							    errorIndex.value = []
							}
							setTimeout(() => {
								
								setSwiperHeight()
							}, 100)
						}
					})
				} else if (res.cancel) {
					console.log('用户点击取消');
					setTimeout(() => {
						setSwiperHeight()
					}, 100)
				}
			}
		});
	}
	const goErrorList = () => {
		uni.showLoading({
			title:'加载中'
		})
		const userInfo = uni.getStorageSync('userInfo')
		uni.request({
			url: util.baseUrl + `/wxapi/wxQuestion/getErrorQuestionNew`,
			method: 'GET',
			data: {
				userId: userInfo._id,
				seriesId: ids.value.seriesId,
				sectionId:ids.value.sectionId
			},
			success: (res) => {
				if (res.data.data.questionArray.length) {
					let record = res.data.data.record
					// record.sort((a,b)=>{
					//   return a.store_check_id.length - b.store_check_id.length
					// })
					console.log('record',record)
					let questionArray = res.data.data.questionArray
					// questionArray.sort((a,b) => {
					// 	return a.type - b.type
					// })
					record.forEach((item1) => {
						questionArray.forEach((item2) => {
							if(item2 && item1) {  // 后端bug有些项返回为null  前端处理
								if (item1.questionId == item2._id && !item2.answered) {
								
									item2.store_check_id = item1.store_check_id
									item2.status = item1.status
									item2.collectStatus = item1.collectStatus
									item2.answered = item1.store_check_id.length > 0
									item2.options.forEach((item3) => {
										// 该选项是否在正确答案中
										if (item2.correct_id.includes(item3
												.select_id)) {
											item3.icon_url = true
											item3.iscorrect = true
										}
										// 该选项是否在选择的答案中
										if (item2.store_check_id.includes(item3
												.select_id)) {
											item3.whetherSubmit = true
										}
										// 如果该选项在选择的答案中且错误
										if (item2.store_check_id.includes(item3
												.select_id) && !item2
											.correct_id
											.includes(item3.select_id)) {
											item3.icon_url = false
											item3.iscorrect = false
										}
									})
								}
							}
							
						})
					})
					
				
					questionArray.sort((a,b) => {
						if(a.type > b.type) {
							return 1
						}else {
							return -1
						}
					})
					questionData.value = questionArray
					uni.hideLoading()
					confirmRedo()
					singleAndMultipleNum()
					
					// const idsStr = JSON.stringify(ids)
					// questionArray.splice(200, 100);
					// const recordnew = encodeURIComponent(JSON.stringify(questionArray))
					// recordnew
					// uni.navigateTo({
					// 	url: `/pages/questionList/questionList?record=${recordnew}&ids=${idsStr}&from="err"`,
					// })
				} else {
					uni.showToast({
						title: '还没有错题，赶紧先做题',
						icon: 'none',
						duration: 1500
					});
					setTimeout(() => {
							uni.navigateBack({
								delta:1
							})
					},1500)
					// setTimeout(() => {
						
					
					// })
				}
	
			}
		})
	}
</script>

<style lang="scss">
	.question {
		background-color: #fff;
		font-size: 30rpx;
		padding: 20rpx;

		.top {
			position: relative;
			margin-top: 20rpx;

			.progress {
				width: 600rpx;
			}

			.top-text {
				position: absolute;
				right: 0;
				top: -15rpx;
				font-size: 26rpx;
				color: #9f9f9f;
			}
		}

		.content {
			.sort-box {
				display: flex;

				.order-time {
					margin-left: 20rpx;
				}

				.note-active {
					color: #ffc639;
				}
			}

			.note-operate {
				display: flex;
				justify-content: space-between;
				border-bottom: 2rpx solid #bfbfbf;
				padding-bottom: 10rpx;
			}

			.submit {
				background-color: #ffc639
			}

			.addNode {
				background-color: #ffc639;
				text-align: center;
				height: 70rpx;
				line-height: 70rpx;
				margin: 20rpx 0;
				border-radius: 10rpx;
			}

			.temp-bottom {
				height: 170rpx;
				width: 100%;
			}

			// overflow: auto;

			.topic-type {
				margin-top: 20rpx;
				width: 120rpx;
				height: 40rpx;
				line-height: 40rpx;
				border-radius: 5rpx;
				background-color: #e3817c;
				text-align: center;
				color: #fff;
				font-size: 26rpx;
			}

			.examQuestion {

				margin: 20rpx 0;
			}

			.select-answer {
				border-radius: 5rpx;
				border: 2rpx solid #9f9f9f;
				padding: 20rpx;
				margin-bottom: 10rpx;
			}

			.selected {
				// color: #fcd22e;
				border: 2rpx solid #fcd22e;
				background-color: #fffbf2;
			}

			.answer-box {
				display: flex;
				margin-top: 20rpx;
				justify-content: space-between;
				padding-bottom: 30rpx;

			}

			.middle {
				border-bottom: 2rpx solid #9f9f9f;

				.collect {
					height: 70rpx;
					border-radius: 10rpx;
					line-height: 70rpx;
					display: flex;
					justify-content: space-between;
					background-color: #fff9e9;
					margin-bottom: 20rpx;

					.collect-button {
						margin-top: 10rpx;
						height: 50rpx;
						padding: 0 20rpx;
						line-height: 50rpx;
						border-radius: 20rpx;
						background-color: #ffc639;
					}
				}
			}

			.other-note,
			.my-note {

				.other-note-title {

					padding-bottom: 20rpx;
					margin-top: 20rpx;
					font-weight: 700;
				}

				.item {
					position: relative;
					margin-bottom: 5rpx;
					border-bottom: 2rpx solid #bfbfbf;
					background-color: #fff;

					.note-top {
						// border-bottom: 1rpx solid #d4d4d4;
						padding: 10rpx 0;

						.img {
							width: 100rpx;
							height: 100rpx;
							border-radius: 50%;
							overflow: hidden;
							image {
								width: 100%;
								height: 100%;
							}
						}

						.user-name {
							position: absolute;
							left: 120rpx;
							top: 10rpx;
						}

						.note-time {
							position: absolute;
							left: 120rpx;
							top: 60rpx;
							font-size: 28rpx;
							color: #9f9f9f;
						}

					}

					.note-content {
						margin-top: 20rpx;
						font-size: 30rpx;
						margin-bottom: 30rpx;
					}

					.note-approve {
						position: absolute;
						display: flex;
						right: 50rpx;
						bottom: 30rpx;
						line-height: 26rpx;
						font-size: 28rpx;
						color: #9f9f9f;

						.approve-num {
							margin-right: 10rpx;
						}

						.img {
							width: 30rpx;
							height: 30rpx;

							image {
								width: 100%;
								height: 100%;
							}
						}
					}

					.note-report {
						position: absolute;
						right: 50rpx;
						top: 20rpx;

						.img {
							width: 30rpx;
							height: 30rpx;

							image {
								width: 100%;
								height: 100%;
							}
						}
					}
				}


			}

			.analyze-title {
				margin-top: 20rpx;
				font-weight: 700;
			}

			.tabs {
				margin-top: 20rpx;

				.tabs-type {
					display: flex;
					justify-content: space-between;

					.item {
						padding-bottom: 10rpx;
					}
				}
			}

			.tab-selected {
				border-bottom: 5rpx solid #ffc639;
			}
		}

		/* 弹出框 */
		.popup-view {
			height: 900rpx;
			overflow-y: auto;
			width: 100%;
			background-color: #ffffff;
			padding: 50rpx 0;

			.yes-text {
				background-color: #5dbf84 !important;
				color: #ffffff;
			}

			.no-text {
				background-color: red !important;
				color: #ffffff;
			}
		}

		.popup-view text {
			background-color: #f7f7f7;
			width: 80rpx;
			height: 80rpx;
			line-height: 80rpx;
			text-align: center;
			border-radius: 50%;
		}

		.multiple,
		.single {
			display: flex;
			justify-content: center;
			align-items: center;
			position: relative;
			margin-bottom: 100rpx;

			.text {
				position: absolute;
				left: 20rpx;
				top: -40rpx;
				font-weight: 700;
			}

			.item {
				display: grid;
				grid-template-columns: repeat(6, auto);
				gap: 45rpx;
				width: fit-content;
				/* 使网格的宽度适应内容 */
			}
		}


		.bottom-operate {
			height: 150rpx;
			width: calc(100% - 40rpx);
			display: flex;
			position: fixed;
			bottom: 0rpx;
			display: flex;
			justify-content: space-between;
			text-align: center;
			font-size: 26rpx;
			background-color: #fff;

			.img {
				width: 80rpx;
				height: 80rpx;

				image {
					width: 100%;
					height: 100%;
				}
			}
		}

		.swiper {
			min-height: 100vh;
		}

		.true {

			border: 2rpx solid #5cc575;
			background-color: #eef9f3;
		}

		.false {
			border: 2rpx solid #ee7b69;
			background-color: #f9e9e9;
		}
	}
</style>